package com.ruoyi.web.controller.business.customer;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.business.base.PageParam;
import com.ruoyi.business.customer.domain.dto.JbFollowupRecordDto;
import com.ruoyi.business.customer.domain.dto.JbFollowupRecordListDto;
import com.ruoyi.business.customer.domain.vo.JbFollowupRecordExportListVo;
import com.ruoyi.business.customer.domain.vo.JbFollowupRecordListVo;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.core.JoR;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.customer.domain.JbFollowupRecord;
import com.ruoyi.business.customer.service.JbFollowupRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 跟进记录 Controller
 *
 * @author ruoyi
 * @date 2024-10-11
 */
@Api("跟进记录")
@RestController
@RequestMapping("/followup_record")
public class JbFollowupRecordController extends BaseController
{
    @Autowired
    private JbFollowupRecordService service;

    /**
     * 查询跟进记录列表
     */
    @ApiOperation("查询跟进计划列表")
    @PreAuthorize("@ss.hasPermi('followup_record:list')")
    @GetMapping("/list")
    public TableDataInfo list(PageParam page, JbFollowupRecordListDto jbFollowupRecord)
    {
        jbFollowupRecord.setDataType(Constants.PUBLIC_NUMBER_0);
        IPage<JbFollowupRecordListVo> voIPage = service.listData(page.b(), jbFollowupRecord);
        return JoR.getDataTable(voIPage);
    }

    /**
     * 导出跟进记录列表
     */
    @ApiOperation("导出跟进记录列表")
    @PreAuthorize("@ss.hasPermi('followup_record:export')")
    @Log(title = "跟进记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PageParam page, JbFollowupRecord jbFollowupRecord)
    {
        LambdaQueryWrapper<JbFollowupRecord> select = new LambdaQueryWrapper<>();
        IPage<JbFollowupRecord> iPage = service.page(page.b(), select);

        List<JbFollowupRecord> list = iPage.getRecords();
        ExcelUtil<JbFollowupRecord> util = new ExcelUtil<JbFollowupRecord>(JbFollowupRecord.class);
        util.exportExcel(response, list, "跟进记录数据");
    }

    /**
     * 获取跟进记录详细信息和其他信息
     */
    @ApiOperation("获取跟进记录详细信息和其他信息")
    @PreAuthorize("@ss.hasPermi('followup_record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(service.getDataInfo(id));
    }
    /**
     * 获取跟进记录详细信息
     */
    @ApiOperation("获取跟进记录详细信息")
    @PreAuthorize("@ss.hasPermi('followup_record:query')")
    @GetMapping(value = "/details/{id}")
    public AjaxResult getDetails(@PathVariable("id") Long id)
    {
        return success(service.getById(id));
    }
    /**
     * 新增跟进计划
     */
    @ApiOperation("新增跟进计划")
    @PreAuthorize("@ss.hasPermi('followup_record:add')")
    @Log(title = "新增跟进计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JbFollowupRecord jbFollowupRecord)
    {
        jbFollowupRecord.setTaskStatus(Constants.JBFOLLOWUPRECORD_TASKSTATUS_1001);
        return toAjax(service.save(jbFollowupRecord));
    }

    /**
     * 修改跟进记录
     */
    @ApiOperation("修改跟进计划")
    @PreAuthorize("@ss.hasPermi('followup_record:edit')")
    @Log(title = "跟进记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JbFollowupRecord jbFollowupRecord)
    {
        return toAjax(service.updateById(jbFollowupRecord));
    }

    /**
     * 删除跟进记录
     */
    @ApiOperation("删除跟进记录")
    @PreAuthorize("@ss.hasPermi('followup_record:remove')")
    @Log(title = "跟进记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(service.removeByIds(Arrays.asList(ids)));
    }
    /**
     * 新增跟进记录
     */
    @ApiOperation("新增跟进记录")
    @PreAuthorize("@ss.hasPermi('followup_record:addRecord')")
    @Log(title = "新增跟进记录", businessType = BusinessType.INSERT)
    @PostMapping(value = "/addRecord")
    public AjaxResult addRecord(@RequestBody JbFollowupRecordDto jbFollowupRecordDto)
    {
        return toAjax(service.saveInfo(jbFollowupRecordDto));
    }
    /**
     * 修改跟进记录
     */
    @ApiOperation("修改跟进记录")
    @PreAuthorize("@ss.hasPermi('followup_record:editRecord')")
    @Log(title = "修改跟进记录", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/editRecord")
    public AjaxResult editRecord(@RequestBody JbFollowupRecordDto jbFollowupRecordDto)
    {
        return toAjax(service.updateInfo(jbFollowupRecordDto));
    }
    /**
     * 删除跟进记录
     */
    @ApiOperation("删除跟进记录")
    @PreAuthorize("@ss.hasPermi('followup_record:remove')")
    @Log(title = "跟进记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/removeRecord/{id}")
    public AjaxResult removeRecord(@PathVariable Long id)
    {
        return toAjax(service.removeRecord(id));
    }
    /**
     * 查询跟进记录列表
     */
    @ApiOperation("查询跟进记录列表")
    @PreAuthorize("@ss.hasPermi('followup_record:recordList')")
    @GetMapping("/recordList")
    public TableDataInfo recordList(PageParam page, JbFollowupRecordListDto jbFollowupRecord)
    {
        IPage<JbFollowupRecordListVo> voIPage = service.recordList(page.b(), jbFollowupRecord);
        return JoR.getDataTable(voIPage);
    }
    /**
     * 导出跟踪记录数据
     */
    @ApiOperation("导出跟踪记录数据")
    @PreAuthorize("@ss.hasPermi('followup_record:export')")
    @Log(title = "导出跟踪记录数据", businessType = BusinessType.EXPORT)
    @PostMapping("/exportRecord")
    public void exportRecord(HttpServletResponse response,PageParam page, JbFollowupRecordListDto jbFollowupRecord)
    {
        List<JbFollowupRecordExportListVo> list = service.exportRecord(page.b(), jbFollowupRecord);
        ExcelUtil<JbFollowupRecordExportListVo> util = new ExcelUtil<JbFollowupRecordExportListVo>(JbFollowupRecordExportListVo.class);
        util.exportExcel(response, list, "跟进记录数据");
    }

}
